<?php

class Admin_TcController extends Zend_Controller_Action {

    public function init() {
        if (!Zend_Auth::getInstance()->hasIdentity()) {
            $this->_redirect("/admin/login");
        }
        $this->_helper->layout->setLayout('admin');
    }

    public function indexAction() {
        $tcDb = new Admin_Model_Tc();
        $tc = $tcDb->getTc();
        $form = new Admin_Form_Tc();
        $form->data->setValue($tc[0]['details']);
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()->getPost())) {
                $values = $form->getValues();
                $tcDb->updateTc(array(
                    'details' =>$values['data'],
                        ), 1);
                $this->view->isDone = true;
            }
        }
    }

    public function aboutusAction() {
        $tcDb = new Admin_Model_Tc();
        $tc = $tcDb->getAboutUs();
        $form = new Admin_Form_Tc();
        $form->data->setLabel("Details of About Us:");
        $form->data->setValue($tc[0]['details']);
        $form->submit->setLabel('Update About Us');
        $this->view->form = $form;
        if ($this->getRequest()->isPost()) {
            if ($form->isValid($this->getRequest()->getPost())) {
                $values = $form->getValues();
                $tcDb->updateTc(array(
                    'details' => $values['data'],
                        ), 2);
                $this->view->isDone = true;
            }
        }
    }

}

